from django.db import models

from apps.classify.models import WorksCategory
from apps.works.models import Work


class Workslb(models.Model):
    image = models.CharField(max_length=200, verbose_name='图片')
    work = models.ForeignKey(Work, verbose_name='作品', on_delete=models.PROTECT, related_name='work')
    status = models.BooleanField(default=True, verbose_name='状态')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_works_lb'
        verbose_name = '轮播作品'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.work.title


class IndexClassify(models.Model):
    name = models.CharField(max_length=20, verbose_name='名称', default="")
    category = models.ForeignKey(WorksCategory, verbose_name='分类', on_delete=models.PROTECT)
    status = models.BooleanField(default=True, verbose_name='状态')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_index_classify'
        verbose_name = '主页分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category.name
